define(['jquery', 'bootstrap', 'backend', 'table', 'form','upload','editable'], function ($, undefined, Backend, Table, Form, Upload)  {
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'feditionreportmonthtwo/index' + location.search,
                    add_url: 'feditionreportmonthtwo/add',
                    edit_url: 'feditionreportmonthtwo/edit',
                    del_url: 'feditionreportmonthtwo/del',
                    multi_url: 'feditionreportmonthtwo/multi',
                    import_url: 'feditionreportmonthtwo/import',
                    table: 'fedition_reportmonth',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'timedate',
                search:false,
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'timedate', title: __('Timedate'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime, datetimeFormat:"YYYY-MM"},
                        {field: 'admin_id', title: __('运营'),visible: false,addClass: "selectpage", extend: "data-source='auth/admin/index' data-field='nickname'"},
                        {field: 'admin_name', title: __('运营'), operate: false},
                        {field: 'material', title: __('采购成本($)'), operate:'BETWEEN',sortable:true},
                        {field: 'freight', title: __('原物流成本￥'), operate:'BETWEEN',sortable:true},
                        {field: 'freightmj', title: __('物流成本($)'), operate:'BETWEEN',sortable:true},
                        {field: 'advertisingz', title: __('广告成本($)'), editable: true, operate: false},
                        {field: 'countnumsz', title: __('总单'), operate:'BETWEEN',sortable:true},
                        {field: 'countnumst', title: __('退款单'), operate:'BETWEEN',sortable:true},
                        {field: 'countnumsw', title: __('未发货单'), operate:'BETWEEN',sortable:true},
                        {field: 'countnums', title: __('单量'), operate:'BETWEEN',sortable:true},
                        {field: 'order_proportion', title: __('单转'), operate:'BETWEEN',sortable:true},
                        // {field: 'status_freight',title: __('物流成本确认'),formatter: Table.api.formatter.toggle,yes: 'normal',no: 'hidden'},
                        // {field: 'status_material',title: __('采购成本确认'),formatter: Table.api.formatter.toggle,yes: 'normal',no: 'hidden'},
                        {field: 'zcost', title: __('Zcost'), operate:'BETWEEN',sortable:true},
                        
                        {field: 'total_price', title: __('原销售额')},
                        {field: 'total_tip_received', title: __('原小费')},
                        {field: 'saleszy', title: __('原总销售额')},
                        {field: 'salesz', title: __('现总销售额($)')},
                        {field: 'salesz_discount', title: __('总销售额($)(95%)'), operate:'BETWEEN',sortable:true},
                        {field: 'gross_profit', title: __('Gross_profit'), operate:'BETWEEN',sortable:true},
                        {field: 'info', title: __('备注'), operate:false},
                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('更新业绩'),
                            table: table,
                            events: Table.api.events.operate,
                            operate: false,
                            buttons: [
                                {
                                    name: 'ajax',
                                    text: __('点击更新业绩'),
                                    title: __('点击更新业绩'),
                                    classname: 'btn btn-sm btn-warning btn-magic btn-ajax',
                                    icon: 'fa fa-leaf',
                                    confirm: '更新业绩会重新更新业绩详情以及采购数量，确认开始更新吗？（更新业绩详情以及采购数量需要十分钟）',
                                    url: 'feditionreportmonthtwo/edit_status',
                                    success: function (data, ret) {
                                        Layer.alert(ret.msg);
                                        //刷新父级页面
                                        // window.parent.location.reload();
                                        //刷新当前页面
                                        table.bootstrapTable('refresh', {});
                                        return true;
                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                }
                            ],
                            formatter: Table.api.formatter.buttons
                        },
                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('业绩详情'),
                            table: table,
                            events: Table.api.events.operate,
                            operate: false,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: __('查看业绩详情'),
                                    title: __('查看业绩详情'),
                                    extend: 'data-area=\'["90%","90%"]\'',
                                    classname: 'btn btn-sm btn-success btn-dialog',
                                    icon: 'fa fa-try fa-fw',
                                    url: 'zyeji/index'
                                },
                                {
                                    name: 'detail',
                                    text: __('查看商品采购数'),
                                    title: __('查看商品采购数'),
                                    extend: 'data-area=\'["90%","90%"]\'',
                                    classname: 'btn btn-sm btn-info btn-dialog',
                                    icon: 'fa fa-try fa-fw',
                                    url: 'zyeji_info/index'
                                }
                            ],
                            formatter: Table.api.formatter.buttons
                        },
                        {field: 'status_yeji', title: __('采购数更新状态'), searchList: {"normal":__('完成'),"hidden":__('更新中')}, formatter: Table.api.formatter.status},
                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});